/*
 * Copyright (C) 2012 Virglinio & Asociados
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.virglinio.telemedicina.rehabilitacion;

import android.app.TabActivity;
import android.content.Intent;
import android.content.res.Resources;
import android.os.Bundle;
import android.util.Log;
import android.view.Window;
import android.view.WindowManager;
import android.widget.TabHost;

import com.virglinio.telemedicina.rehabilitacion.bluetooth.Bluetooth;
import com.virglinio.telemedicina.rehabilitacion.internet.Internet;
import com.virglinio.telemedicina.rehabilitacion.openGL.Rehabilitacion3DOpenGLActivity;
import com.virglinio.telemedicina.rehabilitacion.plot2D.Plot2DActivity;

/**
 * Clase principal del Sistema de Telerehabilitación
 * @author mario virglinio
 *
 */
public class AndroidTelerehabilitationSystem extends TabActivity {
	
	/**
	 * Set to true to add debugging code and logging.
	 */
	private static final boolean DEBUG = true;
	
	/**
	 * The tag we use when logging, so that our messages can be distinguished
	 * from other messages in the log. Public because it's used by several
	 * classes.
	 */
	private static final String LOG = "AndroidTelerehabilitationSystem";

	private static boolean habilitarTabs = false;
	
	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		
		if (DEBUG) {
			Log.e(LOG, "+++ ON CREATE +++");
		}
		
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
		setContentView(R.layout.main);

		Resources res = getResources(); 	// Resource object to get Drawables
		TabHost tabHost = getTabHost();  	// The activity TabHost
		TabHost.TabSpec spec;  				// Resusable TabSpec for each tab
		Intent intent;  					// Reusable Intent for each tab
		
		// Create an Intent to launch an Activity for the tab (to be reused)
		intent = new Intent().setClass(this, Bluetooth.class);
		
		// Initialize a TabSpec for each tab and add it to the TabHost
		spec = tabHost.newTabSpec("conectar").setIndicator("Conectar",
				res.getDrawable(R.drawable.ic_tab_bluetooth))
				.setContent(intent);
		tabHost.addTab(spec);
				
		// Do the same for the other tabs		
		intent = new Intent().setClass(this, Internet.class);
		spec = tabHost.newTabSpec("internet").setIndicator("Internet",
				res.getDrawable(R.drawable.ic_tab_website))
				.setContent(intent);
		tabHost.addTab(spec);
				
		intent = new Intent().setClass(this, Plot2DActivity.class);
		spec = tabHost.newTabSpec("plot2d").setIndicator("Plot 2D",
				res.getDrawable(R.drawable.ic_tab_plot2d))
				.setContent(intent);
		tabHost.addTab(spec);

		intent = new Intent().setClass(this, Rehabilitacion3DOpenGLActivity.class);
		spec = tabHost.newTabSpec("rehabilitacion3d").setIndicator("Rehabilitación 3D",
				res.getDrawable(R.drawable.ic_tab_rehabilitacion3d))
				.setContent(intent);
		tabHost.addTab(spec);

		tabHost.setCurrentTab(0);
		//tabHost.getTabWidget().getChildTabViewAt(1).setEnabled(false);
		//tabHost.getTabWidget().getChildTabViewAt(2).setEnabled(false);
		//tabHost.getTabWidget().getChildTabViewAt(3).setEnabled(false);	
	}
	
	@Override
	protected void onStart() {
		// TODO Auto-generated method stub
		super.onStart();
		if (DEBUG) {
			Log.e(LOG, "+++ ON START +++");
		}
	}
	
	@Override
	protected void onResume() {
		// TODO Auto-generated method stub
		super.onResume();
		if (DEBUG) {
			Log.e(LOG, "+++ ON RESUME +++");
		}
		if (habilitarTabs) {
			//habilitarTodosLosTabs();
		}
	}	
	
	@Override
	protected void onPause() {
		// TODO Auto-generated method stub
		super.onPause();
		if (DEBUG) {
			Log.e(LOG, "+++ ON PAUSE +++");
		}
	}
	
	@Override
	protected void onStop() {
		// TODO Auto-generated method stub
		super.onStop();
		if (DEBUG) {
			Log.e(LOG, "+++ ON STOP +++");
		}
	}
	
	@Override
	protected void onDestroy() {
		// TODO Auto-generated method stub
		super.onDestroy();
		if (DEBUG) {
			Log.e(LOG, "+++ ON DESTROY +++");
		}
	}
	
	public void habilitarTodosLosTabs(){
		TabHost tabHost = getTabHost();  	// The activity TabHost
		tabHost.getTabWidget().getChildTabViewAt(1).setEnabled(true);
		tabHost.getTabWidget().getChildTabViewAt(2).setEnabled(true);
		tabHost.getTabWidget().getChildTabViewAt(3).setEnabled(true);
	}
	
	public static void setHabilitarTabs(boolean habilitarTabs) {
		AndroidTelerehabilitationSystem.habilitarTabs = habilitarTabs;
	}
}